#include <iostream>
#include <vector>
#include <cstring>
#include <queue>

using namespace std;

const int N=5*1e4+10;


vector<pair<int,int>> edge[N];
int dist[N],vis[N];
int n;
void spfa()
{
	memset(dist,-0x3f3f,sizeof(dist));
	dist[0]=0;
	queue<int> st;
	vis[0]=1;
	st.push(0);
	
	
	while(st.size())
	{
		int t=st.front();
		st.pop();
		vis[t]=0;
		for(auto& e:edge[t])
		{
			int x=e.first;
			int w=e.second;
			if(dist[x]<dist[t]+w)
			{
				dist[x]=dist[t]+w;
				if(vis[x]==0)
				{
					st.push(x);
					vis[x]=1;
				}
			}
		}
	}
}
int main()
{
	cin>>n;
	for(int i=1;i<=50001;i++)
	{
		edge[i-1].push_back({i,0});
		edge[i].push_back({i-1,-1});
	}	
	
	for(int i=1;i<=n;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		a++,b++;
		
		edge[a-1].push_back({b,c});
	}
	
	spfa();
	
	cout<<dist[50001]<<endl;
	return 0;
}
